<?php 
function category_view() {
	require("model/categoryBD.php");
	$tab = select_category();
	if(sizeof($tab['id_categ']) > 0) {
		require("view/category.tpl");
	} else {
		$message = "Aucune categorie disponible pour le moment";
		require("view/category.tpl");
	}
}

function category_view_pagination($page) {
	require("model/categoryBD.php");
	$tab = select_category_pagination($page);
	if(sizeof($tab['id_categ']) > 0) {
		require("view/category.tpl");
	} else {
		$message = "Aucune categorie disponible pour le moment";
		require("view/category.tpl");
	}
}

function add_category() {
	if(count($_POST)==0) {
		require("view/category.tpl");
	} else {
		require("model/categoryBD.php");
		if(add_category_db($_POST['name_categ'], $_POST['comment_categ'])) {
			$message = "Categorie inseree.";
			require("view/valid.tpl");
		} else {
			$message = "Categorie deja existante";
			require("view/category.tpl");
		}
	}
}

function delete_category($id_categ) {
	if (isset($id_categ)) {
		require("model/categoryBD.php");
		if (delete_category_db($id_categ)) {
			$message = "Categorie supprimee";
			require("view/valid.tpl");
		} else {
			require("view/category.tpl");
		}
	}
}

function category_view_by_id($id_categ) {
	require("model/categoryBD.php");
	$tab = select_category_by_id($id_categ);
	if(sizeof($tab['id_categ']) > 0) {
		$display = "block";
		require("view/category.tpl");
	} else {
		$message = "Aucune categorie disponible pour le moment";
		require("view/category.tpl");
	}
}

function update_category($id_categ, $name_categ, $comment_categ) {
		if (isset($id_categ) && isset($name_categ) && isset($comment_categ)) {
		require("model/categoryBD.php");
		if (update_category_db($id_categ, $name_categ, $comment_categ)) {
			$message = "Categorie modifie";
			require("view/valid.tpl");
		} else {
			require("view/category.tpl");
		}
	}
}
	

?>